#ifndef __SHM_RARRAY_H
#define __SHM_RARRAY_H

#include <cstdint>
#include <pthread.h>

typedef struct shm_s {
    pthread_mutex_t mutex;
    int32_t count;
    char data[1];
} shm_t;

//Readonly share memory array
template <class T, int32_t max_size>
class RShareMemArray
{
    public:
        RShareMemArray(const char *);
        ~RShareMemArray();

        int32_t Add(T *);
        int32_t Length();
        int Remove(int32_t);
        void Unlink();

        inline char *Name() { return name_; }

        T *operator[](int32_t);

    private:
        char *name_;

        int32_t max_count_;
        int32_t max_element_size_;
        int32_t mmap_size_;
        int shm_fd_;

        shm_t *mem_;
};

#include "rshm_array.cpp"

#endif
